//
//  AppDelegate.m
//  ConvenientlyTake
//
//  Created by 张奇 on 2022/12/20.
//

#import "AppDelegate.h"
#import <AMapFoundationKit/AMapFoundationKit.h>
#import "AppDelegate+JPush.h"
#import "AvoidCrash.h"
#import "LoginVC.h"
#import "FirstLaunchViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [AppDelegate setJPshBadgeWithBadge:0];
    [self getGaoDeMap];
    [self configurationAvoidCrash];
    [QMUIConsole sharedInstance].canShow = NO;
    [self regisJPushWithApplication:application didFinishLaunchingWithOptions:launchOptions];
    
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    BOOL isNotFirstLauch = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNotFirst"];
    if (isNotFirstLauch) {
        if ([TGUserModel getUserEntity] != nil) {
            self.tabarController = [[TGTabBarVC alloc] init];
            [self.window setRootViewController:self.tabarController];
            [self.window makeKeyAndVisible];
        } else {
            LoginVC *loginVC = [[LoginVC alloc] init];
            loginVC.complentBlock = ^{
                self.tabarController = [[TGTabBarVC alloc] init];
                [self.window setRootViewController:self.tabarController];
                [self.window makeKeyAndVisible];
            };
            [self.window setRootViewController:loginVC];
            [self.window makeKeyAndVisible];
        }
        
    }else{
        FirstLaunchViewController *launchvc = [[FirstLaunchViewController alloc] init];
        [self.window setRootViewController:launchvc];
        [self.window makeKeyAndVisible];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isNotFirst"];
    }
    return YES;
}

#pragma mark -高德地图
-(void)getGaoDeMap {
//    [[AMapServices sharedServices] setEnableHTTPS:NO];

    [AMapServices sharedServices].apiKey = GaoDe_AppKey;
    /*
     * 调用隐私合规处理方法
     */
//    [AMapPrivacyUtility handlePrivacyAgreeStatus];
    
}


- (void)configurationAvoidCrash {
    [AvoidCrash becomeEffective];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealWithCrashMessage:) name:AvoidCrashNotification object:nil];
}

- (void)dealWithCrashMessage:(NSNotification *)note {
    //注意:所有崩溃的信息都在userInfo中
    NSLog(@"%@",note.userInfo);
}



@end
